<?php

namespace app\modules\setting\models\workspaces;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper;
use app\modules\setting\models\workspaces\SetWorkspacesYhsp;
use yii\helpers\Json;

/**
 * SetWorkspacesYhspSearch 是 `app\modules\setting\models\workspaces\SetWorkspacesYhsp` 的搜索模型.
 */
class SetWorkspacesYhspSearch extends SetWorkspacesYhsp
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['tk_id', 'description', 'create_time', 'collect_count', 'comment_count', 'digg_count', 'play_count', 'share_count', 'thumbnail', 'display_url', 'video', 'music', 'update_at'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // 绕过scenario()在父类中的实现
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @param integer $pageSize
     *
     * @return ActiveDataProvider
     */
    public function search($params,$select=null)
    {
        $query = SetWorkspacesYhsp::find()->select($select ? $select : "*");

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => ['pageSize' => ArrayHelper::getValue($params,"pageSize",10),'defaultPageSize' => 10,'pageSizeParam' => 'pageSize'],
            'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
        ]);

        $this->load($params,"");

        if (!$this->validate()) {
            // 如果您不想在验证失败时返回任何记录，请取消下面一行的注释
            // $query->where('0=1');
            return $dataProvider;
        }

        // 过滤条件
        $query->andFilterWhere([
            'id' => $this->id,
        ]);


                $query->andFilterWhere(['like', 'tk_id', $this->tk_id])                                ->andFilterWhere(['like', 'description', $this->description])
                                ->andFilterWhere(['like', 'create_time', $this->create_time])
                                ->andFilterWhere(['like', 'collect_count', $this->collect_count])
                                ->andFilterWhere(['like', 'comment_count', $this->comment_count])
                                ->andFilterWhere(['like', 'digg_count', $this->digg_count])
                                ->andFilterWhere(['like', 'play_count', $this->play_count])
                                ->andFilterWhere(['like', 'share_count', $this->share_count])
                                ->andFilterWhere(['like', 'thumbnail', $this->thumbnail])
                                ->andFilterWhere(['like', 'display_url', $this->display_url])
                                ->andFilterWhere(['like', 'video', $this->video])
                                ->andFilterWhere(['like', 'music', $this->music]);
            
        return $dataProvider;
    }
}
